package com.weibo.host.severlet;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.log4j.Logger;

import com.weibo.common.BaseSeverlet;
import com.weibo.zhifa.ZhiFa;
import com.weibo.zhifa.service.ZhifaService;
import com.weibo.zhifa.service.imp.ZhifaServiceImp;

public class SaveTaskHostSeverlet extends BaseSeverlet {
	private static Logger logger = Logger.getLogger(SaveTaskHostSeverlet.class);

	@Override
	public void doService(HttpServletRequest request,
			HttpServletResponse response) {
		logger.info("SaveTaskHostSeverlet 被访问了！");
		try {
			HttpSession session = request.getSession();
			String host_ids = request.getParameter("host_ids");
			ZhiFa zhifa = (ZhiFa) session.getAttribute("zhifa");
			ZhifaService zhifaService = new ZhifaServiceImp();
			zhifa.setHost_ids(host_ids);
			if (zhifaService.addZhifa(zhifa)) {
				request.getRequestDispatcher("/TaskManagerServlet.do").forward(
						request, response);
			} else {
				request.getRequestDispatcher("/index.jsp").forward(request,
						response);
			}
		} catch (ServletException e) {
			logger.error(e);
		} catch (IOException e) {
			logger.error(e);
		}
	}

}
